package com.weixiaoit.web;

import java.io.IOException;
import java.io.PrintWriter;
import java.util.List;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import com.weixiaoit.entity.City;
import com.weixiaoit.entity.Province;
import com.weixiaoit.service.CityService;
import com.weixiaoit.service.ProvinceService;

public class CityServlet extends HttpServlet {

	
	private static final long serialVersionUID = 1L;

	public void doGet(HttpServletRequest request, HttpServletResponse response)
			throws ServletException, IOException {
		request.setCharacterEncoding("UTF-8");
       String province=request.getParameter("province");
   
		province=new String(province.getBytes("ISO-8859-1"),"UTF-8");
		System.out.println(province);
	
		CityService cityService=new CityService();
		List<City> cityList=cityService.findByProvinceId(province);
		for(City city : cityList) {
			System.out.println(city.getCity());
		}
		
		response.setContentType("text/xml;charset=UTF-8");
		PrintWriter out = response.getWriter();
		out.print("<?xml version=\"1.0\" encoding=\"UTF-8\"?>");
		out.print("<data>");
		
		for(City city : cityList) {
			out.print("<citys>");
			out.print("<cityId>"+city.getId() +"</cityId>");
			out.print("<city>"+city.getCity()+"</city>");
			out.print("</citys>");
		}
		
		out.print("</data>");
		out.flush();
		out.close();
		

		
	}

}
